#ifndef _B5M_COMMON_THREAD_MUTEX_H_
#define _B5M_COMMON_THREAD_MUTEX_H_

#include "common.h"
#include "B5M_Mutex.h"

B5M_BEGIN_VERSIONED_NAMESPACE_DECL

class B5M_Export B5M_Thread_Mutex
{
public:
  /// Constructor.
  B5M_Thread_Mutex();

  /// Implicitly destroy the mutex.
  ~B5M_Thread_Mutex (void);

  /**
   * Explicitly destroy the mutex.  Note that only one thread should
   * call this method since it doesn't protect against race
   * conditions.
   */
  int remove (void);

  /// Acquire lock ownership (wait on queue if necessary).
  int acquire (void);

  /**
   * Block the thread until we acquire the mutex or until @a tv times
   * out, in which case -1 is returned with @c errno == @c ETIME.  Note
   * that @a tv is assumed to be in "absolute" rather than "relative"
   * time.  The value of @a tv is updated upon return to show the
   * actual (absolute) acquisition time.
   */
  int acquire (B5M_UINT32 timeout);

  /**
   * Conditionally acquire lock (i.e., don't wait on queue).  Returns
   * -1 on failure.  If we "failed" because someone else already had
   * the lock, @c errno is set to @c EBUSY.
   */
  int tryacquire (void);

  /// Release lock and unblock a thread at head of queue.
  int release (void);

private:
  // = Prevent assignment and initialization.
  B5M_NONE_COPYABLE(B5M_Thread_Mutex);

  B5M_Mutex lock_;
};

typedef B5M_Thread_Mutex B5M_Recursive_Thread_Mutex;

B5M_END_VERSIONED_NAMESPACE_DECL

#endif